package com.haiqi.modules.ship.service;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.dao.CrewUserMapper;
import com.haiqi.common.persistence.entity.CrewUser;
import com.haiqi.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by hythzx on 2016/5/27.
 */
@Service
public class ShipUserService {

    @Autowired
    private CrewUserMapper crewUserMapper;


    public PageInfo<CrewUser> getDataList(CrewUser userInfo, PageBean page){
        PageUtils.generatePage(page);
        List<CrewUser> dataList = crewUserMapper.getDataList(userInfo);
        PageInfo<CrewUser> crewUserPageInfo = new PageInfo<>(dataList);
        return crewUserPageInfo;
    }

    public List<CrewUser> getDataList(CrewUser userInfo){
        List<CrewUser> dataList = crewUserMapper.getDataList(userInfo);
        return dataList;
    }

    /**
     * 获取一个公司的所有的船舶
     * @param companyId 公司ID
     * @param userType 用户类型 1：导航用户；2：监控用户
     * @return
     */
    public List<CrewUser> getListByCompanyId(String companyId,String userType,String shipName){
        List<CrewUser> list=crewUserMapper.getListByCompany(companyId,userType,shipName);
        return list;
    }
    public CrewUser getCrewUserInfo(int id){
        CrewUser userInfo = crewUserMapper.selectByPrimaryKey(id);
        return userInfo;
    }

    public CrewUser selectByUserName(String loginName){
        CrewUser crewUser = crewUserMapper.selectByUserName(loginName);
        return crewUser;
    }


    public boolean update(CrewUser userInfo){
        boolean success = false;
        int count = 0;
        if(userInfo.getId() == null){
            count = crewUserMapper.insertSelective(userInfo);
        }else{
            count = crewUserMapper.updateByPrimaryKeySelective(userInfo);
        }
        if(count > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(int id){
        boolean success = false;
        int count = 0;
        count = crewUserMapper.deleteByPrimaryKey(id);
        if(count > 0){
            success = true;
        }
        return success;
    }
}
